<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../VueJs/vue.js"></script>
</head>

<body>
    <div id="root">
        <h1>显示格式化后的时间</h1>
        <h2>{{getFormatTime()}}</h2>
    </div>
</body>
<script>
    Vue.config.productionTip = false;
    Vue.config.devtools = true;

    const vm = new Vue({
        el: '#root',
        data: {
            time: Date.now()
        },
        methods: {
            getFormatTime: function () {
                const nowTime = new Date(this.time);

                let year = nowTime.getFullYear();

                let month = nowTime.getMonth() + 1;

                month = month < 10 ? '0' + month : month;

                let date = nowTime.getDate();

                date = date < 10 ? '0' + date : date;

                const arr = ['星期天', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
                const day = nowTime.getDay();

                let h = nowTime.getHours();
                h = h < 10 ? '0' + h : h;
                let m = nowTime.getMinutes();
                m = m < 10 ? '0' + m : m;
                let s = nowTime.getSeconds();
                s = s < 10 ? '0' + s : s;
                return `${year}-${month}-${day} ${h}:${m}:${s} ${arr[day]}`
            }
        }
    });
</script>

</html>